package com.cuitrip.business.reminder.proxy;

import android.content.Context;
import android.content.Intent;

import com.cuitrip.business.login.LoginInstance;
import com.cuitrip.business.order.model.OrderItem;
import com.cuitrip.business.reminder.RemindDialogActivity;
import com.cuitrip.business.user.model.CtUserInfo;
import com.cuitrip.push.model.PushMessageModel;
import com.cuitrip.push.model.TypeKeyMap;

/**
 * 提醒相关逻辑
 * Created by ak on 15/9/23.
 */
public class RemindProxy {


    private static RemindProxy sInstance;

    public static RemindProxy getInstance() {
        if (null == sInstance)
            sInstance = new RemindProxy();
        return sInstance;
    }

    public void startReminderDialog(Context context, OrderItem orderItem) {
        CtUserInfo userInfo = LoginInstance.getInstance().getUserInfo();

        PushMessageModel pushMessageModel = new PushMessageModel();

        pushMessageModel.setServiceDate(orderItem.getServiceDate());

        //如果是旅行者，使用对方头像作为发现者头像.反之
        pushMessageModel.setInsiderNick(userInfo.isTravel() ? orderItem.getUserNick() : userInfo.getNick());
        pushMessageModel.setInsiderHeadPic(userInfo.isTravel() ? orderItem.getHeadPic() : userInfo.getHeadPic());

        //如果是发现者，使用对方头像作为旅行者.反之
        pushMessageModel.setTravllerNick(userInfo.isTravel() ? userInfo.getNick() : orderItem.getUserNick());
        pushMessageModel.setTravllerHeadPic(userInfo.isTravel() ? userInfo.getHeadPic() : orderItem.getHeadPic());
        pushMessageModel.setMessageType(TypeKeyMap.kBeginOrderMsg);

        pushMessageModel.setUserType(userInfo.isTravel()?PushMessageModel.TRAVELLER:PushMessageModel.INSIDER);

        Intent activityIntent = new Intent(context, RemindDialogActivity.class);
        activityIntent.putExtra(RemindDialogActivity.DATA_KEY, pushMessageModel);
        activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(activityIntent);
    }


    public void endReminderDialog(Context context, OrderItem orderItem) {

        PushMessageModel pushMessageModel = new PushMessageModel();
        pushMessageModel.setServiceDate(orderItem.getServiceDate());
        pushMessageModel.setServiceName(orderItem.getServiceName());
        pushMessageModel.setUserType(PushMessageModel.INSIDER);
        pushMessageModel.setMessageId(orderItem.getOid());

        pushMessageModel.setMessageType(TypeKeyMap.kEndOrderMsg);

        Intent activityIntent = new Intent(context, RemindDialogActivity.class);
        activityIntent.putExtra(RemindDialogActivity.DATA_KEY, pushMessageModel);
        activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(activityIntent);
    }

}
